<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: allen.qiang
// +----------------------------------------------------------------------

/**
 * 会员发票ajax类
 * @package  ajax/comm/customer
 * @author   allen.qiang
 */

quanli_require('module/base/customer/custInvoice.class.php');

class ajax_invoice {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch($_REQUEST['operFlg']) {

                case 1: //新增或修改发票
                    $this->edit();
                    break;

                case 2: //删除发票
                    $this->delete();
                    break;

                default:
                    $this->toReturn('参数错误');
                    break;

            }

        } else {

            $this->toReturn('参数错误');

        }

    }

    /**
     * 返回信息
     * @param string $message
     * @param int $code
     * @param mixed $data
     */
    private function toReturn( $message, $code = 400, $data = '' ) {

        die( json_encode( array( 'code' => $code, 'message' => $message, 'data' => $data ) ) );

    }

    /**
     * 新增或修改发票
     */
    private function edit() {

        global $G_PGLOB;

        if (!isset($_REQUEST['pcustID']) || !is_numeric($_REQUEST['pcustID']))
            die( json_encode( array( 'code' => 406, 'message' => '参数错误' ) ) );

        //实例发票类
        $custInvoice = new custInvoice( $G_PGLOB->DBCA );

        //添加/修改会员发票信息
        $_REQUEST['creator'] = $G_PGLOB->currentUserID;
        $result_array = $custInvoice->editCustInvoice( $_REQUEST );

        echo json_encode($result_array);

    }

    /**
     * 删除会员收货地址
     */
    private function delete() {

        if (!isset($_REQUEST['pcustID']) || !is_numeric($_REQUEST['pcustID']))
            die( json_encode( array( 'code' => 406, 'message' => '参数错误' ) ) );

        if (!isset($_REQUEST['id']) || !is_numeric($_REQUEST['id']))
            die( json_encode( array( 'code' => 400, 'message' => '缺少参数' ) ) );

        global $G_PGLOB;

        //实例发票类
        $custInvoice = new custInvoice( $G_PGLOB->DBCA );

        //删除发票信息
        $result_array = $custInvoice->delCustInvoice($_REQUEST['pcustID'], $_REQUEST['id']);

        echo json_encode( $result_array );

    }

}